package com.test.mvc;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.test.bean.BookInfo;
import com.test.bean.UserBookInfo;

@Component
public class BookService extends SqlSessionDaoSupport implements BookDao{

	@Override
	public List<BookInfo> findBook(BookInfo bi) throws Exception {
		// TODO Auto-generated method stub
		SqlSession sqlsession = this.getSqlSession();
		return sqlsession.selectList("com.test.daomvc.BookDao.findBook", bi);
	}

	@Override
	public void save(BookInfo bi) throws Exception {
		// TODO Auto-generated method stub
		SqlSession sqlsession = this.getSqlSession();
		if(bi.getId()==0)
			sqlsession.selectList("com.test.daomvc.BookDao.saveBook", bi);
		else
			sqlsession.selectList("com.test.daomvc.BookDao.updateBook", bi);
	}

	@Override
	public void delete(Integer id) throws Exception {
		// TODO Auto-generated method stub
		SqlSession sqlsession = this.getSqlSession();
		sqlsession.selectList("com.test.daomvc.BookDao.deleteBook", id);
	}

	@Override
	public List<UserBookInfo> findUserBook(String uid) throws Exception {
		SqlSession sqlsession = this.getSqlSession();
		return sqlsession.selectList("com.test.daomvc.BookDao.findUserBook", uid);
	}

	@Override
	public void saveUserBook(UserBookInfo bi) throws Exception {
		// TODO Auto-generated method stub
		SqlSession sqlsession = this.getSqlSession();
		sqlsession.selectList("com.test.daomvc.BookDao.saveUserBook", bi);
	}


}
